|
|
|
|
|
|
|
To try this out, remove the call to the CloseFile() method from the cmdRead_Click() event and then step through this event procedure to see what happens as you step through the End Sub of that event. |
|
|
|
|
|
|
|
|
Warning About Global Objects |
|
|
|
|
|
|
|
|
When you declare global objects, you must be careful to explicitly release them prior to shutting down your application. If you use the Visual Basic End statement, your global objects Class_Terminate() events will not be fired. If you let your last form unload by itself, the Class_Terminate() event will be fired. However, its always a good practice to explicitly set all global objects equal to Nothing prior to closing your application. |
|
|
|
 |
|
|
|
|
TIP Set all global objects equal to Nothing prior to terminating your application. |
|
|
|
|
|
|
|
|
To test this, create a form, a BAS file, and a class with a Class_Terminate() event in it. Use the End statement to kill the application. You wont see the Class_Terminate() event fire. |
|
|
|
|
|
|
|
|
Default Methods and Properties |
|
|
|
|
|
|
|
|
Most of the controls you use in your Visual Basic projects have a default property. This means that you dont need to specify the name of the procedure when using the object. For example, the following two lines of code are equivalent: |
|
|
|
 |
|
|
|
|
MsgBox txtFirstName.Text
MsgBox txtFirstName |
|
|
|
|
|
|
|
|
There is a trade-off when using the default propertyits less readable, but it involves a little less typing. It used to be that not using the property was more efficient, but that has gone away starting with Visual Basic 5. Therefore, its really just a style issue now of whether you want to use it. |
|
|
|
|
|
|
|
|
To create a default method or property, you need to set the procedure ID of that method or property to become the default. To do this, select Tools, Procedure Attributes from the Visual Basic menu. You should see a form that looks like the one shown in Figure 20.5. |
|
|
|
|
|